<template>
    <van-cell class="van-field" :title="config.label" :required="config.must">
        <van-radio-group v-model="config.value">
            <van-radio v-for="(i,n) in config.data" :key="n" :name="i.value">{{i.text}}</van-radio>
        </van-radio-group>
    </van-cell>
</template>

<script>
export default {
  props: ['config'],
  created() {
    if (this.config.key == 'sex') {
      this.$store.commit('SET_SEX', this.config.value);
    }
    if (this.config.key == 'discuss') {
      this.$store.commit('SET_ISDISCUSS', this.config.value);
    }
    if (this.config.key == 'isDietary') {
      this.$store.commit('SET_ISDIETARY', this.config.value);
    }
  },
  watch: {
    'config.value': function(val, oldVal) {
      if (this.config.key == 'sex') {
        this.$store.commit('SET_SEX', val);
      }
      if (this.config.key == 'discuss') {
        this.$store.commit('SET_ISDISCUSS', val);
      }
      if (this.config.key == 'isDietary') {
        this.$store.commit('SET_ISDIETARY', val);
      }
    }
  }
};
</script>

<style>
.van-cell .van-radio-group {
  display: flex;
  justify-content: flex-end;
}
.van-cell .van-radio {
  margin: 0 0 0 15px;
}
.van-cell .van-radio .van-icon-checked {
  color: #37acff;
}
.van-radio .van-radio__input {
  line-height: 1em;
}
</style>
